package cn.chenxiejia;

import java.io.*;

/***
 * @program: maven
 * @ClassName: File10
 * @Description: 合并java文件到一个文件中
 * @Author: chenxiejia
 * @Date: 2022/1/19 17:03
 * @version : V1.0
 */
public class File10 {
    public static void main(String[] args) {
        count(new File("F:/jdk"));

    }

    public static void add() {

    }

    public static void count(File file) {
        for (File t : file.listFiles()) {
            if (t.isDirectory()) {
                count(t);
            } else {
                if (t.getName().lastIndexOf(".java") != -1) {
                    try (var br1 = new BufferedReader(new FileReader(t)); var br = new BufferedReader(new FileReader(t)); var bw = new BufferedWriter(new FileWriter("F:/jdk.txt", true))) {
                        bw.write("-----------------------------------------------------------------------------" + String.format("%n"));
                        bw.write("项目名称：" + t.getName() + String.format("%n"));
                        bw.write("项目路径：" + t.getAbsolutePath() + String.format("%n"));
                        bw.write("项目行数：" + br1.lines().count() + String.format("%n"));
                        bw.write("-----------------------------------------------------------------------------" + String.format("%n"));
                        while (br.ready()) {
                            bw.write(String.format("%n") + br.readLine());
                        }
                        bw.write(String.format("%n"));
                        bw.write(String.format("%n"));
                        bw.write(String.format("%n"));
                        bw.write(String.format("%n"));
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }
}
